<?php

header("Content-type: application/xhtml+xml");

require_once('../lib/Smarty/Smarty.class.php');
require_once('../lib/People.php');
require_once('../lib/Schedule.php');
require_once('../lib/Util.php');
require_once('../lib/Constants.php');
require_once('../lib/Config.php');

$data   = make_page(array_merge($_GET, $_POST));
$smarty = new Smarty();
$smarty->assign($data);
$smarty->display($data['error_code'] ? 'error.tmpl' : 'edit_hima.tmpl');

function make_page ($params) {
    $data = array(
        'error_code' => 0
    );

    if (!validate_signature(array_merge($params, $_POST))) {
        $data['error'] = 1;
        return $data;
    }

    if (!isset($params['date']) || !is_date($params['date'])) {
        $data['error'] = 1;
        return $data;
    }

    $date = $params['date'];
    $user = $params['opensocial_owner_id'];

    //get own hima_status
    $own_hima = Schedule::get_list($user, $date, $date);



    $data['own_hima_status'] = count($own_hima) ? $own_hima[0][flag] : 3;
    $data['own_hima_id']     = count($own_hima) ? $own_hima[0][id] : 0;
    $data['date']            = $date;
    $data['friends']         = $friend_hash;
    $data['url_prefix'] = URL_PREFIX;

    $data['analytics']    = '<img src="' . googleAnalyticsGetImageUrl() . '" />'; // for google analytics

    return $data;
}

?>
